<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改密码 - 账户安全中心</title>
    <style>
        /* 全局样式重置与基础设置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', system-ui, sans-serif;
        }

        body {
            background-color: #f0f2f5;
            background-image: 
                radial-gradient(circle at 10% 20%, rgba(79, 70, 229, 0.05) 0%, transparent 20%),
                radial-gradient(circle at 90% 80%, rgba(79, 70, 229, 0.05) 0%, transparent 20%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        /* 主容器样式 */
        .box {
            width: 100%;
            max-width: 450px;
            background-color: #ffffff;
            border-radius: 12px;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
            padding: 35px;
            transition: all 0.3s ease;
        }

        .box:hover {
            box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
        }

        /* 标题样式 */
        .box h2 {
            color: #1e293b;
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 8px;
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        .box h2::before {
            content: "🔐";
            font-size: 26px;
        }

        .subtitle {
            color: #64748b;
            font-size: 14px;
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid #f1f5f9;
        }

        /* 表单组样式 */
        .form-group {
            margin-bottom: 22px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #334155;
            font-size: 15px;
            font-weight: 500;
        }

        /* 输入框样式 */
        .form-control {
            width: 100%;
            padding: 13px 15px;
            padding-right: 45px; /* 为密码可见图标预留空间 */
            border: 1px solid #e2e8f0;
            border-radius: 8px;
            font-size: 15px;
            color: #1e293b;
            transition: all 0.25s ease;
            background-color: #f8fafc;
        }

        .form-control:focus {
            outline: none;
            border-color: #4f46e5;
            box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
            background-color: #ffffff;
        }

        .form-control::placeholder {
            color: #94a3b8;
            font-size: 14px;
        }

        /* 密码可见性切换按钮 */
        .toggle-password {
            position: absolute;
            right: 15px;
            top: 40px;
            background: transparent;
            border: none;
            color: #94a3b8;
            cursor: pointer;
            font-size: 18px;
            transition: color 0.2s ease;
        }

        .toggle-password:hover {
            color: #4f46e5;
        }

        /* 密码强度提示 */
        .password-strength {
            margin-top: 6px;
            font-size: 13px;
            height: 16px;
            display: flex;
            align-items: center;
        }

        .strength-weak {
            color: #ef4444;
        }

        .strength-medium {
            color: #f59e0b;
        }

        .strength-strong {
            color: #10b981;
        }

        /* 按钮样式 */
        .btn-group {
            display: flex;
            gap: 12px;
            margin-top: 25px;
        }

        .btn {
            flex: 1;
            padding: 12px 0;
            border: none;
            border-radius: 8px;
            font-size: 15px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            text-align: center;
            text-decoration: none;
        }

        .btn-primary {
            background-color: #4f46e5;
            color: #ffffff;
        }

        .btn-primary:hover {
            background-color: #4338ca;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
        }

        .btn-primary:active {
            transform: translateY(0);
            box-shadow: 0 2px 6px rgba(79, 70, 229, 0.2);
        }

        .btn-secondary {
            background-color: #f1f5f9;
            color: #334155;
        }

        .btn-secondary:hover {
            background-color: #e2e8f0;
            transform: translateY(-2px);
        }

        .btn-secondary:active {
            transform: translateY(0);
        }

        /* 消息提示样式 */
        .message {
            padding: 12px 15px;
            border-radius: 8px;
            font-size: 14px;
            margin-bottom: 20px;
            text-align: center;
            animation: fadeIn 0.3s ease;
        }

        .error {
            color: #dc2626;
            background-color: #fee2e2;
            border: 1px solid #fecaca;
        }

        .success {
            color: #059669;
            background-color: #dcfce7;
            border: 1px solid #bbf7d0;
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        /* 响应式适配 */
        @media (max-width: 480px) {
            .box {
                padding: 25px 20px;
                margin: 0 15px;
            }

            .box h2 {
                font-size: 22px;
            }

            .form-group {
                margin-bottom: 18px;
            }

            .btn-group {
                flex-direction: column;
                gap: 10px;
            }

            .toggle-password {
                top: 38px;
                font-size: 16px;
            }
        }
    </style>
    <script>
        // 密码可见性切换与强度检测
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const oldPwdInput = document.getElementById('oldPwd');
            const newPwdInput = document.getElementById('newPwd');
            const toggleOldPwd = document.getElementById('toggleOldPwd');
            const toggleNewPwd = document.getElementById('toggleNewPwd');
            const strengthText = document.getElementById('strengthText');

            // 密码可见性切换函数
            function togglePasswordVisibility(input, button) {
                const type = input.getAttribute('type') === 'password' ? 'text' : 'password';
                input.setAttribute('type', type);
                button.textContent = type === 'password' ? '👁️' : '👁️‍🗨️';
            }

            // 绑定切换事件
            toggleOldPwd.addEventListener('click', () => {
                togglePasswordVisibility(oldPwdInput, toggleOldPwd);
            });

            toggleNewPwd.addEventListener('click', () => {
                togglePasswordVisibility(newPwdInput, toggleNewPwd);
            });

            // 密码强度检测
            function checkPasswordStrength(password) {
                let strength = 'weak';
                if (password.length >= 8) {
                    strength = 'medium';
                    // 检测是否包含字母、数字和特殊字符
                    if (/[A-Za-z]/.test(password) && /\d/.test(password) && /[^A-Za-z0-9]/.test(password)) {
                        strength = 'strong';
                    }
                }
                
                // 更新强度显示
                if (password.length === 0) {
                    strengthText.textContent = '';
                    strengthText.className = 'password-strength';
                } else {
                    const strengthLabels = {
                        weak: '密码强度：弱（建议至少8位，包含字母、数字和特殊字符）',
                        medium: '密码强度：中（添加特殊字符可提高安全性）',
                        strong: '密码强度：强（符合安全标准）'
                    };
                    strengthText.textContent = strengthLabels[strength];
                    strengthText.className = `password-strength strength-${strength}`;
                }
            }

            // 监听新密码输入
            newPwdInput.addEventListener('input', function() {
                checkPasswordStrength(this.value);
            });
        });
    </script>
</head>
<body>
    <div class="box">
        <h2>修改密码</h2>
        <p class="subtitle">更新您的密码以增强账户安全性</p>

        <form action="SellerServlet?method=updatePwd" method="post">
            <!-- 错误提示 -->
            <c:if test="${not empty error}">
                <p class="message error">${error}</p>
            </c:if>
            
            <!-- 成功提示 -->
            <c:if test="${not empty msg}">
                <p class="message success">${msg}</p>
            </c:if>

            <!-- 原密码 -->
            <div class="form-group">
                <label for="oldPwd">原密码</label>
                <input type="password" id="oldPwd" name="oldPwd" class="form-control" required 
                       placeholder="请输入当前密码">
                <button type="button" id="toggleOldPwd" class="toggle-password">👁️</button>
            </div>

            <!-- 新密码 -->
            <div class="form-group">
                <label for="newPwd">新密码</label>
                <input type="password" id="newPwd" name="newPwd" class="form-control" required 
                       placeholder="请输入8-20位新密码">
                <button type="button" id="toggleNewPwd" class="toggle-password">👁️</button>
                <div id="strengthText" class="password-strength"></div>
            </div>

            <!-- 按钮组 -->
            <div class="btn-group">
                <button type="submit" class="btn btn-primary">确认修改</button>
                <a href="SellerServlet?method=showDashboard" class="btn btn-secondary">返回</a>
            </div>
        </form>
    </div>
</body>
</html>
